<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var reg = /^\s*$/;
        var a = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$/;
        var b = /^\d+$/;
        var c = /^\w+@[0-9A-Za-z]+[.]com$/;

        function f() {
            document.getElementById("unF").innerHTML = "";
            document.getElementById("pwdF").innerHTML = "";
            document.getElementById("rpwdF").innerHTML = "";
            document.getElementById("yxF").innerHTML = "";
            var f1 = run("un", "用户名");
            var f2 = run("pwd", "密码");
            var f3 = run("rpwd", "确认密码");
            var f4 = run("yx", "邮箱");
            if (f2 && f3) {
                var pwd = document.getElementById("pwd").value;
                var rpwd = document.getElementById("rpwd").value;
                if (pwd != rpwd) {
                    document.getElementById("rpwdF").innerHTML = "必须和密码保持一致";
                    return false;
                }
            }
            if (!a.test(document.getElementById("un").value)) {
                document.getElementById("unF").innerHTML = "必须是6位以上字母数字组合";
                return false;
            }
            if (b.test(document.getElementById("rpwd").value)) {
                document.getElementById("rpwdF").innerHTML = "密码不能是纯数字";
                return false;
            }
            if (!c.test(document.getElementById("yx").value)) {
                document.getElementById("yxF").innerHTML = "邮箱格式不正确";
                return false;
            }
            return f1 && f2 && f3 && f4;
        }

        function run(nid, name) {
            var un = document.getElementById(nid);
            if (reg.test(un.value)) {
                document.getElementById(nid + "F").innerHTML = "不能为空";
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<form onsubmit="return f()">
    <table width="50%">
        <tr>
            <td>
                用户名:<input id="un" type="text"/>
                <font id="unF" color="red"></font>
            </td>
        </tr>
        <tr>
            <td>
                密码:<input id="pwd" type="password"/>
                <font id="pwdF" color="red"></font>
            </td>
        </tr>
        <tr>
            <td>
                确认密码:<input id="rpwd" type="password"/>
                <font id="rpwdF" color="red"></font>
            </td>
        </tr>
        <tr>
            <td>
                邮箱:<input id="yx" type="text"/>
                <font id="yxF" color="red"></font>
            </td>
        </tr>
    </table>
    <input type="submit"/>
    <input type="reset"/>
</form>
</body>
</html>